class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> mypq;
        for(auto s:stones)
        {
            mypq.push(s);
        }
        while(mypq.size()>1)
        {
            int maxs=mypq.top();
            mypq.pop();
            int Second_largest=mypq.top();
            mypq.pop();
            if(maxs>Second_largest)  mypq.push(maxs-Second_largest);
        }
        return mypq.empty()?0:mypq.top();
    }
};